package demo.vo;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 时间范围的接口
 * 
 * @author hanjy
 *
 */
public class TimeRange implements Serializable {

    private static final long serialVersionUID = 1L;

    /** 最小时间 */
    private LocalDateTime min;
    /** 最大时间 */
    private LocalDateTime max;

    @Override
    public String toString() {
        return "TimeRange [min=" + min + ", max=" + max + "]";
    }

    public TimeRange() {
        super();
    }

    public TimeRange(LocalDateTime min, LocalDateTime max) {
        super();
        this.min = min;
        this.max = max;
    }

    /**
     * 拓展时间范围
     * 
     * @param target
     */
    public void merge(TimeRange that) {
        if (that == null) {
            return;
        }
        LocalDateTime tmin = that.getMin();
        LocalDateTime smin = this.getMin();
        boolean ok = tmin != null && tmin.compareTo(smin) < 0;
        if (ok) {
            this.setMin(tmin);
        }
        LocalDateTime tMax = that.getMax();
        LocalDateTime sMax = this.getMax();
        ok = tMax != null && tMax.compareTo(sMax) > 0;
        if (ok) {
            this.setMax(tMax);
        }
    }

    public LocalDateTime getMin() {
        return min;
    }

    public void setMin(LocalDateTime min) {
        this.min = min;
    }

    public LocalDateTime getMax() {
        return max;
    }

    public void setMax(LocalDateTime max) {
        this.max = max;
    }

}
